package org.txazo.blog.commons.parse;

import java.io.*;

public class JavaScriptParser {

	public static int FLAG = 0; // 字符串标记
	public static int TAG = 0; // 标签标记
	public static int COMM = 0; // 注释标记

	public static void main(String[] args) {
		readHtml(new File(JavaParser.class.getResource("").getPath()
				.replaceFirst("bin", "src")
				+ "source/parse.js"));
	}

	public static void readHtml(File file) {
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(new FileInputStream(
					file), "UTF-8"));
			String temp = null;
			System.out.print("<span class=\"xml-pln\">");
			while ((temp = br.readLine()) != null) {
				parseHtml(temp);
			}
			System.out.print("</span>");
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void parseHtml(String line) {
		if (line.equals("")) {
			// 空行
		} else {
			// 非空行
			// 补全空格
			int i = 0;
			int length = line.length();
			for (; i < length; i++) {
				if (!(line.charAt(i) == 9)) {
					break;
				}
			}
			i *= 4;
			for (int j = 0; j < i; j++) {
				System.out.print(" ");
			}
			// 去掉前后空格
			// String trim = line.trim();

		}
		System.out.println("");
	}

}
